package cn.tedu.hwrabbitmq.config;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

@Configuration
public class RabbitConfiguration {

//    定义正常Queue,Exchange,Routing_Key字符串
    public static final String EXCHANGE_NAME = "test-add-exchange-";
    public static final String QUEUE_NAME = "test-add-queue-";
    public static final String ROUTING_KEY = "t-a-q-";

    public RabbitConfiguration() throws IOException, TimeoutException {
    }

//    //    定义正常exchange-Direct
//    @Bean
//    public DirectExchange orderExchangeDirect(){
//        Boolean durable = true;
//        Boolean autoDel = false;
//        return new DirectExchange(EXCHANGE_NAME+"0",durable,autoDel);
//    }

    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        factory.setVirtualHost("/");
        Connection connection = factory.newConnection();
        return connection;
    }



}
